package com.zrf.testchatgpt.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrf.testchatgpt.entity.UserEmploy;
import com.zrf.testchatgpt.mapper.UserEmployMapper;
import com.zrf.testchatgpt.util.Result;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zrf
 * @since 2023-03-15
 */
@RestController
@RequestMapping("/employ")
@RequiresRoles(value = {"user","admin"},logical= Logical.OR)
public class UserEmployController {
    @Resource
    UserEmployMapper employMapper;

    @GetMapping("getAllEmployByPage")
    @RequiresPermissions("select_Employ")
    public Result getAllEmploy(@Param("size") Integer size,@Param("page") Integer page){
        LambdaQueryWrapper<UserEmploy> userLambdaQueryWrapper = Wrappers.lambdaQuery();
//        userLambdaQueryWrapper.select(User::getUsername).like(User::getUsername , "k");

        Page<UserEmploy> mapPage = new Page<>(page , size , false);
        IPage<UserEmploy> mapIPage = employMapper.selectPage(mapPage , userLambdaQueryWrapper);
        return result(mapIPage);
    }
    @PostMapping("getEmployByID")
    public Result getEmployByID(String userId){
        LambdaQueryWrapper<UserEmploy> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(UserEmploy::getUserId,userId);
        List<UserEmploy> userEmploys = employMapper.selectList(wrapper);
       return result(userEmploys);
    }
    public  static Result result(Object res){
        if(res!=null){
            return new Result("200","查询成功",res);
        }
        return new Result("500","查询失败",null);
    }

}

